Eth2 Phase 1: How to Calculate Base Fee
References:
About a shard transition
About the structures of various components
A base fee is calculated from shard_block_length of the new block.
The calculated base fee is used in the next block.
code:py
def compute_updated_gasprice(prev_gasprice: Gwei, shard_block_length: uint64) -> Gwei:
if shard_block_length > TARGET_SHARD_BLOCK_SIZE:
delta = (prev_gasprice * (shard_block_length - TARGET_SHARD_BLOCK_SIZE)
// TARGET_SHARD_BLOCK_SIZE // GASPRICE_ADJUSTMENT_COEFFICIENT)
return min(prev_gasprice + delta, MAX_GASPRICE)
else:
delta = (prev_gasprice * (TARGET_SHARD_BLOCK_SIZE - shard_block_length)
// TARGET_SHARD_BLOCK_SIZE // GASPRICE_ADJUSTMENT_COEFFICIENT)
return max(prev_gasprice, MIN_GASPRICE + delta) - delta
As shard_block_length = transition.shard_block_lengths[i], compute_updated_gasprice(prev_gasprice, shard_block_length).
What is the shard_block_length calculated from?
Side note: The shard_block_lengths is a member of ShardTransition.
code:py
class ShardTransition(Container):
# Starting from slot
start_slot: Slot
# Shard block lengths
# Shard data roots
# Intermediate shard states
# Proposer signature aggregate
proposer_signature_aggregate: BLSSignature
The type of shard_block_lengths is List[uint64, MAX_SHARD_BLOCKS_PER_ATTESTATION].
MAX_SHARD_BLOCKS_PER_ATTESTATION is len(SHARD_BLOCK_OFFSETS), and SHARD_BLOCK_OFFSETS is List[uint64, 12]([1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]).
Therefore, MAX_SHARD_BLOCKS_PER_ATTESTATION is 12. #? Side note: What is SHARD_BLOCK_OFFSETS?
The function for updating a shard state calculates shard_block_length.
code:py
def process_shard_block(shard_state: ShardState,
block: ShardBlock) -> None:
"""
Update shard_state with shard block.
"""
shard_state.slot = block.slot
prev_gasprice = shard_state.gasprice
shard_block_length = len(block.body)
shard_state.gasprice = compute_updated_gasprice(prev_gasprice, uint64(shard_block_length))
if shard_block_length != 0:
shard_state.latest_block_root = hash_tree_root(block)
Side note: ShardState has three members: slot, gasprice, and latest_block_root.
code:py
class ShardState(Container):
slot: Slot
gasprice: Gwei
latest_block_root: Root
Thus, the above function updates the three members of ShardState.
As for latest_block_root, if the length of the shard block is 0, the latest_block_root will not updated. In other words, the latest_block_root is the root of the previous block.
What is the case where shard_block_length is zero?
shard_block_length is the length of the new block body.
shard_block_length = len(block.body)
What is the block body?
The body is data to be stored.
code:py
class ShardBlock(Container):
shard_parent_root: Root
beacon_parent_root: Root
slot: Slot
shard: Shard
proposer_index: ValidatorIndex
Type: ByteList[MAX_SHARD_BLOCK_SIZE]
MAX_SHARD_BLOCK_SIZE: 2^20 = 1,048,576
TARGET_SHARD_BLOCK_SIZE: 2^18 = 262,144
What is the body format?
ByteList
code:py
class ByteList(RawBytesView, FixedByteLengthViewHelper, View):
def __new__(cls, *args, **kwargs):
byte_limit = cls.limit()
out = super().__new__(cls, *args, **kwargs)
if len(out) > byte_limit:
raise Exception(f"incorrect byte length: {len(out)}, cannot be more than limit {byte_limit}")
return out
(snip)
How are transactions be grouped into a shard block (body)? #?